#include <stdio.h>
#include <stdlib.h>
#include "TutorialConfig.h"
#ifdef USE_MYMATH
#include "MathFunctions/MathFunctions.h"
#endif
/**
* power - Calculate the power of number.
* @param base: Base value.
* @param exponent: Exponent value.
*
* @return base raised to the power exponent.
*/
int mod = 1337;

double power(double base, int exponent) {
    base =  base - (int)(base / mod) * mod;
    double res = 1;
    for(int _ = 0; _ < exponent; _++) {
        res *= base;
        res = res - (int)(res / mod) * mod;
    }
    return res;
}

int mypow(int base, int exponent) {
    if ( exponent == 0)
        return 1;
    if ( exponent % 2 == 1) {
        return base * mypow(base, exponent - 1);
    } else {
        int sub = mypow(base, exponent / 2);
        return sub * sub;
    }
}

int main_1(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: %s base exponent \n", argv[0]);
        return 1;
    }
    printf("%s Version %d.%d\n", argv[0], 
                                 Tutorial_VERSION_MAJOR,
                                 Tutorial_VERSION_MINOR);
    int base = atoi(argv[1]);
    int exponent = atoi(argv[2]);
    int result = mypow(base, exponent);
    printf("%d ^ %d is %d\n", base, exponent, result);
    return 0;
}

int main(int argc, char *argv[]) {
    if (argc < 2) {
        printf("Usage: %s base\n", argv[0]);
        return 1;
    }
    printf("%s Version %d.%d\n", argv[0], 
                                 Tutorial_VERSION_MAJOR,
                                 Tutorial_VERSION_MINOR);
    double base = atof(argv[1]);
    double result = mysqrt(base);
    printf("sqrt %g is %g\n", base, result);
    return 0;
}

